package com.ll.spring5.aopanno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 2020/9/9 - 13:28
 */
//增强的类
@Component
@Aspect //生成代理对象
@Order(3) //设置对同一个类中的同一个方法增强的优先级
public class UserProxy {
    
    //相同切入点抽取
    @Pointcut(value = "execution(* com.ll.spring5.aopanno.User.add(..))")
    public void pointDemo() {
        
    }
    
    //前置通知
//    @Before(value="execution(* com.ll.spring5.aopanno.User.add(..))")
    @Before(value = "pointDemo()")
    public void before() {
        System.out.println("before()......");
    }

    //方法执行之后执行,不管是否发生异常,都会执行
    //最终通知
    @After(value="execution(* com.ll.spring5.aopanno.User.add(..))")
    public void after() {
        System.out.println("After()...");
    }

    //在方法返回值后执行
    //后置通知(返回通知)
    @AfterReturning(value="execution(* com.ll.spring5.aopanno.User.add(..))")
    public void afterReturning() {
        System.out.println("afterReturning()...");
    }

    //异常通知,在被增强的方法发生异常时执行
    @AfterThrowing(value="execution(* com.ll.spring5.aopanno.User.add(..))")
    public void afterThrowing() {
        System.out.println("afterThrowing()...");
    }

    //环绕通知
    //环绕在方法前后,环绕前,在before之前,环绕后,在After之后
    @Around(value="execution(* com.ll.spring5.aopanno.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
        System.out.println("Around()环绕之前...");

        //被增强的方法执行
        proceedingJoinPoint.proceed();

        System.out.println("Around()环绕之后...");
    }

    //

}
